/*******************************************************************************
 * Copyright (c) 2007 University of Oslo.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     University of Oslo - initial API and implementation
 *******************************************************************************/

package com.cea.papyrus.diagram.sequence.sedi.edit.manager;


import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.tools.CellEditorLocator;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.swt.widgets.Text;

import com.cea.papyrus.diagram.sequence.sedi.figures.LifelineFigure;

/**
 * Special CellEditorLocator for Lifelines because it contains two editable
 * labels.
 * 
 * @author Andreas Limyr 
 * @author frankd@ifi.uio.no
 */
public class LifelineCellEditorLocator implements CellEditorLocator {

	private final LifelineFigure figure;
	private final int target;
	
	public LifelineCellEditorLocator(final LifelineFigure f, final int target) {
		this.figure = f;
		this.target = target;
	}
	
	public void relocate(CellEditor celleditor) {
		Text text = (Text)celleditor.getControl();
		
		final Rectangle r;
		if (target == LifelineFigure.TARGET_REF)
			r = figure.getRefBounds();
		else
			r = figure.getLabelBounds();

		org.eclipse.swt.graphics.Rectangle trim = 
			text.computeTrim(r.x, r.y, r.width, r.height);
		
		text.setBounds(trim.x, trim.y, trim.width, trim.height);		
	}
}
